import React, { Component } from 'react';

export default class excelName extends Component {
  textFn = () => {
    const { name = '' } = this.props;
    const pos = name.lastIndexOf('/');
    const str = name.substr(pos + 1);
    const last = str.lastIndexOf('.');
    const text = str.substring(0, last);
    let newName = str.substring(0, last - 2);
    if (text.length > 20) {
      newName = `${text.substring(0, 16)}...`;
    }

    return (
      <div
        style={{
          color: '#1890ff',
          cursor: 'pointer',
          userSelect: 'none',
          display: 'flex',
        }}
        title={str}
      >
        <div style={{ textOverflow: 'ellipsis', whiteSpace: 'nowrap', overflow: 'hidden' }}>
          {newName}
        </div>
        <div> {str.substring(last - 2)}</div>
      </div>
    );
  };
  render() {
    return <div>{this.textFn()}</div>;
  }
}
